<template>
<div id="all_company">
	<div class="top">
		<div class="container">
			<div class="cont_t">
				<p>{{ $lang("ALL_COMPANY") }}</p>
		 		<el-input 
		 			v-model="keyword" 
		 			:placeholder="$lang('SEARCH_COMPANY')"
		 		>
		 		<el-button slot="append" type="danger" @click="getList()"><img src="../../assets/img/search.png" alt="$lang('LATEST_BLOCKS')"><span>{{ $lang("SEARCH") }}</span></el-button>
		 		</el-input>
			</div>
		</div>
	</div>
	<div class="bot">

		<div class="container">
			<el-table
		    :data="list"
		    style="width: 100%;border:10px;background-color: #212C4F;"
            :empty-text="$lang('NODATA')"
		  	:row-style="{
		  		'border':'none',
		  		'background-color':'#1D2748',
		  		'border-bottom':'none',
		  		'text-align':'center',
		  	}"	
		  	>
		    <el-table-column
		      prop="companyWalletAddress"
		      :label="$lang('WALLET_ADDRESS')"
		      width="550">
               <template scope='scope' ><router-link style="cursor: pointer;color: #cca33c;" :to="{path:'/account/sender/' + scope.row.companyWalletAddress }">{{ scope.row.companyWalletAddress }}</router-link></template>
		    </el-table-column>

		    <el-table-column
		      :label="$lang('COMPANY_NAME')"
		      width="300">
		      <template scope='scope'><span style="cursor: pointer;color: #cca33c;" @click="setCompanyId(scope.row.companyId,scope.row.companyZhName)">{{$i18n.locale === 'zh'?scope.row.companyZhName:scope.row.companyEnName}}</span></template>
		    </el-table-column>

		    <el-table-column
		      prop="companyZhName"
		      :label="$lang('TRANSACTE_INFO')"
		      width="250">
		      <template scope='scope' ><span style="cursor: pointer;color: #cca33c;" @click="TradingInfo(scope.row.companyWalletAddress)">{{scope.row.tradingCount}}</span></template>
		    </el-table-column>

		    <el-table-column
		      width="70">
		      <template scope='scope' ><span style="cursor: pointer;color: #cca33c;" @click="TradingInfo(scope.row.companyWalletAddress)">>></span></template>
		    </el-table-column>

		  </el-table>
		  <el-pagination
		    layout="prev, pager, next"
		    :total="totalPage*10" @current-change="getList">
		  </el-pagination>
		</div>
	</div>
	
</div>
</template>

<script>
import { gets } from "@/api/api.js";
export default {
  data() {
    return {
      list: null,
      pageNo: 1,
      pageSize: 10,
      keyword: "",
      totalPage: 0
    };
  },
  methods: {
    async getList(type) {
        try {
            // 获取企业列表
            let res = await gets.searchCompanyList("/company/search.json", {
                pageNo: type,
                pageSize: this.pageSize,
                keyword: this.keyword
            });
            this.list = res.data.list
            this.totalPage = res.data.totalPage
        } catch (e) {
            throw e;
        }
    },
    setCompanyId: function(ID,companyName) {
        let that = this
        that.$store.commit('setCompanyid', ID)
        that.$store.commit('setCompanyname', companyName)
        // localStorage.setItem("companyId", ID); 
        that.$router.push({ path: '/companyInfo'})
    },
    TradingInfo: function(ID) {
        let that = this
        // localStorage.setItem("companyId", ID); 
        that.$router.push({ path: '/transaction',query: {company: ID}})
    }
  },
  created() {
    this.getList(this.pageNo);
    this.$l();
  },
};
</script>

<style scoped lang="scss">
@import "~assets/scss/all_company.scss";
</style>